<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>首页 </title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link href="css/materialdesignicons.min.css"  th:href="@{/css/materialdesignicons.min.css}" rel="stylesheet">
    <link href="css/style.min.css" th:href="@{/css/style.min.css}" rel="stylesheet"></head>

<body>
<div class="lyear-layout-web" id="mainContent">
    <div th:replace="~{main::rightbar}"></div>
    <div th:replace="~{main::topbar}"></div>
    <div class="lyear-layout-container">

        <header class="lyear-layout-header" th:fragment="topbar">

            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> 项目组成员管理 </span>
                    </div>
                    <div th:replace="~{main::bar}"></div>


                </div>
            </nav>

        </header>

        <main class="lyear-layout-content">


            <div class="container-fluid">



                <div class="row">

                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <h4>成员列表</h4>
                            </div>
                            <div class="card-body">

                                <table>

                                        <td>

                                            <a class="btn btn-primary m-r-5" th:href="@{/userandteamadd}"><i class="mdi mdi-plus"></i> 新增</a>


                                        </td>

                                </table>

                                <div class="table-responsive">

                                    <table class="table table-hover" >

                                        <thead>
                                        <tr>
                                            <th>编号</th>
                                            <th>级别</th>
                                            <th>创建时间</th>
                                            <th>姓名</th>
                                            <th>删除</th>
                                        </tr>
                                        </thead>
                                        <tbody id="boby">

                                        <!--<tr>
                                            <td>8</td>
                                            <td>Logo设计</td>
                                            <td>10/02/2019</td>
                                            <td>01/03/2019</td>
                                            <td><span class="label label-warning">完成</span></td>
                                            <td>
                                                <div class="progress progress-striped progress-sm">
                                                    <div class="progress-bar progress-bar-success" style="width: 100%;"></div>
                                                </div>
                                            </td>
                                        </tr>-->
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>

<!--图表插件-->
<script type="text/javascript" src="js/Chart.js"></script>

<script type="text/javascript">
    //别忘了导入该用的js文件
    subForm();
    function subForm() {

        $.ajax({

            url: '/userandteam', //请求的url
            type: 'get', //请求的方式
            //form表单里要提交的内容，里面的input等写上name就会提交，这是序列化
            cache : false,
            async : true,
            error:function (data) {
                alert('请求失败');
            },
            success:function (data) {
                console.log(data)
                var str1 = "";
                //清空table中的html
                $("#boby").html("");
                for(var i = 0;i<data.length;i++){
                    if(data[i].grade==1)
                    {
                        data[i].grade='开发人员'
                    }else if(data[i].grade==2)
                    {
                        data[i].grade='测试人员'
                    }
                    else if(data[i].grade==3)
                    {
                        data[i].grade='项目经理'
                    }
                    str1 = "<tr>" +
                        "<td>"+data[i].id + "</td>" +
                        "<td>"+data[i].grade + "</td>" +
                        "<td>"+data[i].createdate + "</td>" +
                        "<td>"+data[i].realname + "</td>" +
                        "<td>"+"<a onclick='deleteuserandteam("+data[i].id+")'"+"style=' height: 21px;\n" +
                        "            line-height: 21px;\n" +
                        "            padding: 0 11px;\n" +
                        "            background-color: #33cabb;\n" +
                        "           border-color: #33cabb;\n" +
                        "            color: #fff!important;\n" +
                        "            border-radius: 3px;\n" +
                        "            display: inline-block;\n" +
                        "            text-decoration: none;\n" +
                        "            font-size: 12px;\n" +
                        "            outline: none;'>删除</a>"+"</td>" +

                        "</tr>";
                    $("#boby").append(str1);
                }
            }
        });
    }
    function deleteuserandteam(id){

        $.ajax({
            type:'delete',
            url:'/userandteam/'+id,
            // data:user,
            //contentType:'application/json;charset=UTF-8',

            async : true,
            // global:false,
            success:function(json){
                alert('删除成功');
                subForm();
            },
            error: function (data) {
                alert('删除失败');
            },
        });


    }

</script>
</body>

</html>